package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.BaiComment;
import com.ruoyi.system.service.IBaiCommentService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 评论Controller
 * 
 * @author saruri
 * @date 2024-09-01
 */
@RestController
@RequestMapping("/comment")
public class BaiCommentController extends BaseController
{
    @Autowired
    private IBaiCommentService baiCommentService;

    /**
     * 查询评论列表
     */
   
    @GetMapping("/list")
    public TableDataInfo list(BaiComment baiComment)
    {
        baiComment.setChecked(1);  // 设置 checked=1
        startPage();
        List<BaiComment> list = baiCommentService.selectBaiCommentList(baiComment);
        return getDataTable(list);
    }

    @GetMapping("/listAll")
    public TableDataInfo list2(BaiComment baiComment)
    {
        startPage();
        List<BaiComment> list = baiCommentService.selectBaiCommentList(baiComment);
        return getDataTable(list);
    }

    /**
     * 导出评论列表
     */
    @RequiresPermissions("system:comment:export")
    @Log(title = "评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaiComment baiComment)
    {
        List<BaiComment> list = baiCommentService.selectBaiCommentList(baiComment);
        ExcelUtil<BaiComment> util = new ExcelUtil<BaiComment>(BaiComment.class);
        util.exportExcel(response, list, "评论数据");
    }

    /**
     * 获取评论详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baiCommentService.selectBaiCommentById(id));
    }

    /**
     * 新增评论
     */
    @RequiresPermissions("system:comment:add")
    @Log(title = "评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaiComment baiComment)
    {
        return toAjax(baiCommentService.insertBaiComment(baiComment));
    }

    /**
     * 新增评论
     */
    @RequiresPermissions("system:comment:add")
    @Log(title = "审核评论", businessType = BusinessType.INSERT)
    @PostMapping("/checked")
    public AjaxResult checked(@RequestBody BaiComment baiComment)
    {
        return toAjax(baiCommentService.updateBaiComment(baiComment));
    }

    /**
     * 修改评论
     */
    @RequiresPermissions("system:comment:edit")
    @Log(title = "评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaiComment baiComment)
    {
        return toAjax(baiCommentService.updateBaiComment(baiComment));
    }

    /**
     * 删除评论
     */
    @RequiresPermissions("system:comment:remove")
    @Log(title = "评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baiCommentService.deleteBaiCommentByIds(ids));
    }
//TAG_START:BaiComment_Mine_list

// 控制器
@GetMapping("/mine")
public TableDataInfo listMine(BaiComment baiComment) {
    startPage();
    baiComment.setUserId(SecurityUtils.getUserId());
    List<BaiComment> list = baiCommentService.selectBaiCommentListMine(baiComment);
    return getDataTable(list);
}

//TAG_END:BaiComment_Mine_list


}
